package com.limanyik.family.common.sinterface.impl;

import com.limanyik.family.common.sinterface.UserUtilInterface;
import com.limanyik.family.common.sinterface.entity.WebUserData;
import com.limanyik.family.common.utils.InteriorEncryptUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import static com.limanyik.family.common.utils.InteriorEncryptUtil.MD5;

/**
 * web 用户信息实缓存现类
 */
@Service
public class WebUserUtilInterfaceImpl implements UserUtilInterface<WebUserData> {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public WebUserData getUserCacheData(String token) {
        String key = InteriorEncryptUtil.encrypt(token, MD5);
        return (WebUserData) redisTemplate.opsForValue().get(key);
    }

    @Override
    public boolean setUserCacheData(WebUserData webUserData, String key) {
        redisTemplate.opsForValue().set(key, webUserData);
        return true;
    }
}
